<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Admin\Traits\AdminTrait;
use App\Http\Requests\Admin\BaseRequest;
use App\Http\Service\SchoolsService;
use Illuminate\Support\Facades\Log;

class SchoolController extends AdminController
{
    use AdminTrait;

    /**
     * @desc 学校（增删改）
     */
    public function operate(BaseRequest $request, SchoolsService $schoolService)
    {
        try {
            $result = $schoolService->handler($request->all());

            return $this->success($result);
        } catch (\Exception $e) {
            Log::error($request->route()->uri, ['errMsg' => $e->getMessage(), 'params' => $request->all()]);
            return $this->error([$e->getCode(), $e->getMessage()]);
        }
    }

    /**
     * @desc 学校列表
     */
    public function list(BaseRequest $request, SchoolsService $schoolService)
    {
        try {
            $input = $request->all();
            $this->getPageAndSize($input);

            $result = $schoolService->getList($request->all(), $this->skip, $this->size);
            return $this->success($result);
        } catch (\Exception $e) {
            Log::error($request->route()->uri, ['errMsg' => $e->getMessage(), 'params' => $request->all()]);
            return $this->error([$e->getMessage(), $e->getCode()]);
        }
    }

    /**
     * @desc学校详情
     */
    public function info(BaseRequest $request, SchoolsService $schoolService)
    {
        try {
            $result = $schoolService->getDetail($request->all());
            return $this->success($result);
        } catch (\Exception $e) {
            Log::error($request->route()->uri, ['errMsg' => $e->getMessage(), 'params' => $request->all()]);
            return $this->error([$e->getMessage(), $e->getCode()]);
        }
    }


}
